-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add title type #397
base: trunk
Are you sure you want to change the base?
Add title type #397
Conversation
Signed-off-by: brookewp <[email protected]>
Test this PR in WordPress Playground. |
This is great, and would definitely help with auto-generation! What do you think about |
return sanitize_text_field( strval( $value ) ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return sanitize_text_field( strval( $value ) ); |
$bindings['paragraphs'][] = [ | ||
'content' => [ $field, $name ], | ||
]; | ||
break; | ||
|
||
case 'title': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should remove the "autodetect" above and encourage use of this type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dig it too.
What do you think about string:title or something like that? Like a type with hinting instead of a separate type. We could extend the same hints for other types like id:primary, image_url:primary, string:description, etc.
I like encoded it in the type as well. The only danger there is that you limit yourself in the future by tying it to another primitive type. For example, maybe we decided later that you wanted to indicate a level alongside the title, e.g. 'title' => [ 'level' => 'h1', 'content' => 'My title' ]
I pushed up a small fix in 311223f to supply the missing type definition and to close a loophole that allowed you to provide invalid types to the Validator
.
After seeing the missing name field in #396, I thought it might make sense to add a 'title' type to the schema to set explicit titles. In DataViews, there are three special fields:
When these are set, they get unique styling, which we are utilizing for
image_url
in themediaField
, which can be seen in the screenshots below.This way, we don't have to guess like we do for block patterns. However, I left the check under
string
for sources like Airtable and Google Sheets, where we aren't explicitly defining each field and its type.